<div
	style="min-height: 300px; padding-bottom: 20px; width: 98%; float: left"
	class="portlet x12">
<div class="portlet-header">
<h4>Danh sách danh mục
<div class="buttonrow" style="float: right; margin-right: 20px;"><a
	href="<?php
	echo base_url ();
	?>admin/categories/add_cat"><input type="button"
	value="Thêm danh mục mới" class="btn btn-orange"></a></div>
</h4>
</div>
<!-- .portlet-header -->
<div class="portlet-content">
<table cellpadding="0" cellspacing="0" align="center"
	style="width: 100%;">
	<tr>
		<td style="width: 100%;">
		<table cellpadding="0" cellspacing="0" align="center"
			style="width: 100%;">
			<thead>
				<tr>
					<!--			<th>ID</th>-->
					<th style="width: 70%;">Tên danh mục</th>
					<th>Chức năng</th>
					<!--			<th>S&#7855;p X&#7871;p</th>-->
				</tr>
			</thead>
	<?php
	if (count ( $categories ) > 0) {
		?>
	<?php
	foreach ( $categories as $cat ) {
			?>
		<tr>
				<!--			<td><?php
				echo $cat['id'];
			?></td>-->
				<td style="width: 70%;">
				<div id="div_cat_name_<?php
				echo $cat['id'];
				?>" style="font-size:14px;"><?php
				echo $cat['name'];
			?>
				</div>
				</td>
				<td><?php // echo $cat->order;				?>
				<input type="button" value="Sửa" class="btn btn-green"
					onclick="edit_info('<?php echo $cat['id']; ?>','cat')">&nbsp; <input
					type="button" value="Xoá" class="btn btn-red"
					onclick="del_item('<?php echo $cat['id']; ?>','cat')">
				</td>
			</tr>
	<?php
	}
		?>
	<?php
	} else {
		?>
		<tr class="fontGL row0">
				<td colspan="3"><span style="font-size: 14px;">Không có danh mục</span></td>

		</tr>
	<?php
	}
	?>

		</table>
		</td>
	</tr>
</table>
</div>

<!--END main-->
<script>
function edit_info(id,type){
	document.location.href="<?php
	echo base_url ();
	?>admin/categories/edit_"+type+"/"+id;
}

function save_edit(id,type){
	var _name=document.getElementById(type+"_name_"+id).value;
	$.post(
	"<?php
	echo base_url ();
	?>categories/admin/categories/edit_"+type,
	{
		id: id,
		name:_name
	},
	function(data){
		if(type =='cat')
		str_name='<a href="javascript:void(0);" style="text-decoration:none; font-size: 13px;" onclick="showProduct(\''+id+'\')">'+_name+'</a>';
		else
		str_name=_name;
		document.getElementById("div_"+type+"_name_"+id).innerHTML=str_name;
	}
	);
}

function showProduct(catid){
	$.post(
	"<?php
	echo base_url ();
	?>categories/admin/categories/list_product",
	{catid : catid},
	function(data){
		document.getElementById("list_product").innerHTML=data;
	}
	);
}
function del_item(id,type){
	if(type=='prod'){
		var store_del = confirm("Xoa san pham ?");
	}else{
		var store_del = confirm("Xoá danh mục ?");
	}
	if(store_del==true){
		window.location="<?php echo base_url();?>admin/categories/del_"+type+"/"+id;
	}else{
		return false;
	}
}
</script>